﻿function showModal(title, url) {

	var options = SP.UI.$create_DialogOptions();

	options.title = title;

	options.width = 800;

	options.height = 600;

	//autosize=true;

	options.url = url;

	SP.UI.ModalDialog.showModalDialog(options);

}
//LoadSodByKey("SP.UI.ApplicationPages.Calendar.js", function () {
//    WaitForCalendarToLoad();
//});

 
//function WaitForCalendarToLoad() {
//    colorCalendarEventLinkIntercept();
//}
ExecuteOrDelayUntilScriptLoaded(colorCalendarEventLinkIntercept, 'sp.ui.js');
function colorCalendarEventLinkIntercept() {

    if (SP.UI.ApplicationPages.CalendarNotify.$4a) {

        var OldCalendarNotify =

    SP.UI.ApplicationPages.CalendarNotify.$4a;

        SP.UI.ApplicationPages.CalendarNotify.$4a = function () {

            OldCalendarNotify();

            colorCalendarEventLinks();
            //doModifyCalendar();

        }

    }

    if (SP.UI.ApplicationPages.CalendarNotify.$4b) {

        var OldCalendarNotify =

    SP.UI.ApplicationPages.CalendarNotify.$4b;

        SP.UI.ApplicationPages.CalendarNotify.$4b = function () {

            OldCalendarNotify();
            setInterval(function () { colorCalendarEventLinks() }, 2000);
           // setInterval(function () { doModifyCalendar() }, 2005);


        }

    }

}

function colorCalendarEventLinks() {

    $('div.ms-acal-item[title*="Demo10"]').addClass("calColor1");

    $('div.ms-acal-item[title*="SubSite1"]').addClass("calColor2");

    $('div.ms-acal-item[title*="SubSite2"]').addClass("calColor3");

    $('div.ms-acal-item[title*="SubSite3"]').addClass("calColor4");

    $('div.ms-acal-item[title*="SubSite4"]').addClass("calColo5");
    $('div.ms-acal-item[title*="SubSite5"]').addClass("calColor5");

    $('div.ms-acal-item[title*="SubSite6"]').addClass("calColor7");
    $('div.ms-acal-item[title*="SubSite7"]').addClass("calColo8");

    $('div.ms-acal-item[title*="SubSite8"]').addClass("calColor9");
    $('div.ms-acal-item[title*="SubSite9"]').addClass("calColor10");
    $('div.ms-acal-item[title*="SubSite10"]').addClass("calColor11");
    $('div.ms-acal-item[title*="SubSite11"]').addClass("calColor12");
}

function doModifyCalendar() {
    //DEBUG - $(".ms-acal-rootdiv").css("border", "2px green solid");
    //BEBUG - $(".ms-acal-sdiv").css("border", "2px red solid");�
    // find all of the tags of type sdiv. this will INCLUDE both StartTime and StartTime-EndTime tags...
    $(".ms-acal-sdiv").each(function () {
        // get the raw HTML, which includes the unwanted text ahead of the <a> tag...
        var innerContents = $(this).html();
        //console.log("innerContents = " + innerContents);
        // match the pattern against the returned HTML to return (remember it's an ARRAY of hits) ONLY the HTML containing (and including) the ANCHOR tag...
        var subString = innerContents.match(/<A.+<\/A>/);
        //console.log("subString[0] = " + subString[0]);
        // set this to be the NEW value of the  HTML for this element, thereby REMOVING the annoying timestamp :-)  ...
        $(this).html(subString[0]);
    });

}



 _spBodyOnLoadFunctionNames.push('colorCalendarEventLinkIntercept');

//_spBodyOnLoadFunctionNames.push('doModifyCalendar');